package com.hazardSoft.eStore.ejb;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import com.hazardSoft.eStore.bussines.ProductsBO;
import com.hazardSoft.eStore.common.exception.SystemException;
import com.hazardSoft.eStore.entities.Product;
import com.hazardSoft.eStore.interfaces.ProductsLocal;

/**
 * Session Bean implementation class ProductsEJB
 */
@Stateless
public class ProductsEJB implements ProductsLocal {

	public static final String EJB_NAME = ProductsEJB.class.getSimpleName()+"Local";
	
	@PersistenceContext(unitName = "EStoreJPA")
	private EntityManager entityManager;
	private ProductsBO productsBO;
    /**
     * Default constructor. 
     */
    public ProductsEJB() {
       productsBO = new ProductsBO();
    }

	/**
     * @throws SystemException 
	 * @see ProductsLocal#removeProduct(Product)
     */
    public boolean removeProduct(Product product) throws SystemException {
        
		return productsBO.removeProduct(product, entityManager);
    }

	/**
     * @throws SystemException 
	 * @see ProductsLocal#searchProductbyId(Product)
     */
    public Product searchProductbyId(Product product) throws SystemException {
        
		return productsBO.searchProductbyId(product, entityManager);
    }

	/**
     * @throws SystemException 
	 * @see ProductsLocal#searchProductbyName(Product)
     */
    public Product searchProductbyName(Product product) throws SystemException {
        
		return productsBO.searchProductbyName(product, entityManager);
    }

	/**
     * @throws SystemException 
	 * @see ProductsLocal#updateProduct(Product)
     */
    public Product updateProduct(Product product) throws SystemException {
        
		return productsBO.updateProduct(product, entityManager);
    }

	/**
     * @throws SystemException 
	 * @see ProductsLocal#insertProduct(Product)
     */
    public Product insertProduct(Product product) throws SystemException {
        
		return productsBO.insertProduct(product, entityManager);
    }

	/**
     * @throws SystemException 
	 * @see ProductsLocal#listProducts()
     */
    public List<Product> listProducts() throws SystemException {
        
		return productsBO.listProducts(entityManager);
    }

	public List<Product> searchProducts(Product product) throws SystemException {
		
		return productsBO.searchProducts(product, entityManager);
	}

}
